using System.Threading.Tasks;
using PlaywrightSharp.Transport.Channels;

namespace PlaywrightSharp
{
    /// <summary>
    /// Coverage gathers information about parts of JavaScript and CSS that were used by the page..
    /// </summary>
    public class ChromiumCoverage : ICoverage
    {
        private readonly PageChannel _channel;

        internal ChromiumCoverage(PageChannel channel)
        {
            _channel = channel;
        }

        /// <summary>
        /// Start the CSS coverage.
        /// </summary>
        /// <param name="resetOnNavigation"> Whether to reset coverage on every navigation. Defaults to true.</param>
        /// <returns>A <see cref="Task"/> that resolves when the coverage started.</returns>
        public Task StartCSSCoverageAsync(bool resetOnNavigation = true)
            => _channel.StartCSSCoverageAsync(resetOnNavigation);

        /// <summary>
        /// Start the JS coverage.
        /// </summary>
        /// <param name="resetOnNavigation"> Whether to reset coverage on every navigation. Defaults to true.</param>
        /// <param name="reportAnonymousScripts">Whether anonymous scripts generated by the page should be reported. Defaults to false.</param>
        /// <returns>A <see cref="Task"/> that resolves when the coverage started.</returns>
        public Task StartJSCoverageAsync(bool resetOnNavigation = true, bool reportAnonymousScripts = false)
            => _channel.StartJSCoverageAsync(resetOnNavigation, reportAnonymousScripts);

        /// <summary>
        /// Stop processing the CSS coverage.
        /// </summary>
        /// <returns>A <see cref="Task"/> that resolves to the coverage result.</returns>
        public Task<CSSCoverageEntry[]> StopCSSCoverageAsync() => _channel.StopCSSCoverageAsync();

        /// <summary>
        /// Stop processing the JS coverage.
        /// </summary>
        /// <returns>A <see cref="Task"/> that resolves to the coverage result.</returns>
        public Task<JSCoverageEntry[]> StopJSCoverageAsync() => _channel.StopJSCoverageAsync();
    }
}
